package demo06Object;

public class TestStudent {
    public static void main(String[] args) {

        //1.getClass()方法
        Student s1 = new Student("aaa",20);
        Student s2 = new Student("bbb",22);
        //判断s1和s2是不是同一个类型
        Class class1 = s1.getClass();
        Class class2 = s2.getClass();
        if(class1 == class2){
            System.out.println("s1和s2属于同一个类型");
        }else {
            System.out.println("s1和s2不属于同一个类型");
        }
        System.out.println("============================");

        //2.hasCode()方法
        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());
        Student s3 = s1;
        System.out.println(s3.hashCode());
        System.out.println("============================");

        //3.toString()方法
        System.out.println(s1.toString());
        System.out.println(s2.toString());

        //4.equals()方法
        //hashCode()如果相等，对象的值不一定相等
        //但是如果equals()比较对象的内容相等，那么HashCode一定相等
        //如果重写了equalser而没有重写HashCode，那么就算Hash值一样也会不一样
        System.out.println("============================");
        Student s4 = new Student("通话", 23);
        Student s5 = new Student("重地", 23);
        System.out.println(s4.hashCode());
        System.out.println(s5.hashCode());
        System.out.println(s4.hashCode() == s5.hashCode());
        System.out.println(s4.equals(s5));

        //5.finalize()方法
        Object o = new Object();

    }
}
